package ArrayTest;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Random;

public class BubbleSort {
    public static void main(String[] args) {
        int [] arr=new int[50];
        for (int i = 0; i < arr.length; i++) {
            arr[i]=new Random().nextInt(100);
        }
        System.out.println(Arrays.toString(arr));
        int swapCount=0,compareCount=0;
//        int [] arr={8,5,3,6,8,9,4,7,2,4};
        long startTime=System.currentTimeMillis();
        for (int i = 0; i < arr.length-1; i++) {
            for (int j = 0; j < arr.length-1-i;j++) {
                compareCount++;
                if (arr[j]-arr[j+1]>0){
                    int t;
                    t=arr[j];
                    arr[j]=arr[j+1];
                    arr[j+1]=t;
                    swapCount++;
                }
            }
//            System.out.println(Arrays.toString(arr));
//            System.out.println("比较次数："+compareCount+"交换次数:"+swapCount);
        }
        long endTime=System.currentTimeMillis();
        System.out.println(endTime-startTime);

    }
}
